﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KSOAdmin.Models.Core
{
    /// <summary>
    /// web返回消息泛型版本
    /// </summary>
    /// <typeparam name="Tele"></typeparam>
    public class ResponseModel<Tele>
    {
        /// <summary>
        ///  状态码
        /// </summary>
        public int code { get; set; } = 200;

        /// <summary>
        /// 操作是否成功
        /// </summary>
        public bool isSuccess { get; set; } = true;

        /// <summary>
        /// 返回信息
        /// </summary>
        public string msg { get; set; } = "执行成功";

        /// <summary>
        /// 返回数据集合
        /// </summary>
        public Tele? data { get; set; } = default(Tele);

        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="msg">消息</param>
        /// <returns></returns>
        public static ResponseModel<Tele> Success(string msg,int code=200)
        {
            return Message(true, msg, default, code);
        }
        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="msg">消息</param>
        /// <returns></returns>
        public static ResponseModel<Tele> Success( int code = 200)
        {
            return Message(true, "操作成功", default, code);
        }
         
        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="response">数据</param>
        /// <returns></returns>
        public static ResponseModel<Tele> Success(string msg, Tele response,int code=200)
        {
            return Message(true, msg, response, code);
        }
        /// <summary>
        /// 返回失败
        /// </summary>
        /// <param name="msg">消息</param>
        /// <returns></returns>
        public static ResponseModel<Tele> Fail(string msg, int code = 500)
        {
            return Message(false, msg, default, code);
        }
        /// <summary>
        /// 返回失败
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="response">数据</param>
        /// <returns></returns>
        public static ResponseModel<Tele> Fail(string msg, Tele response, int code=500)  
        {
            return Message(false, msg, response, code);
        }
        /// <summary>
        /// 自定义返回消息
        /// </summary>
        /// <param name="success">失败/成功</param>
        /// <param name="msg">消息</param>
        /// <param name="response">数据</param>
        /// <returns></returns>
        public static ResponseModel<Tele> Message(bool success, string msg, Tele response,int code=500)
        {
            return new ResponseModel<Tele>() { msg = msg, data = response, isSuccess = success, code = code };
        }
    }


    /// <summary>
    /// web 返回消息
    /// </summary>
    public class ResponseModel
    {
       /// <summary>
       /// code
       /// </summary>
        public int code { get; set; } = 200;
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool isSuccess { get; set; } = true;
        /// <summary>
        /// 消息
        /// </summary>
        public string msg { get; set; } = "执行成功";
        /// <summary>
        /// 数据服务
        /// </summary>
        public object? data { get; set; } = null;

        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="status">status</param>
        /// <returns></returns>
        public static ResponseModel Success(string msg,int status=200)
        {
            return Message(true, msg, default, status);
        }
        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="status">status</param>
        /// <returns></returns>
        public static ResponseModel Success(int status = 200)
        {
            return Message(true, "操作成功", default, status);
        }
        /// <summary>
        /// 返回成功
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="response">数据</param>
        /// <returns></returns>
        public static ResponseModel Success(string msg, object response, int status = 200)
        {
            return Message(true, msg, response, status);
        }
        /// <summary>
        /// 返回失败
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="status">status</param>
        /// <returns></returns>
        public static ResponseModel Fail(string msg,int status=500)
        {
            return Message(false, msg, default, status);
        }
        /// <summary>
        /// 返回失败
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="response">数据</param>
        /// <param name="status">数据</param>
        /// <returns></returns>
        public static ResponseModel Fail(string msg, object response, int status = 500)
        {
            return Message(false, msg, response, status);
        }
        /// <summary>
        /// 自定义返回消息
        /// </summary>
        /// <param name="success">失败/成功</param>
        /// <param name="msg">消息</param>
        /// <param name="response">数据</param>
        /// <returns></returns>
        public static ResponseModel Message(bool success, string msg, object response,int status)
        {
            return new ResponseModel() { msg = msg, data = response, isSuccess = success , code = status };
        }
    }


}
